< previous page page_455 next page >

Page 455
'
FileCopyError:
'
If ErrorCheck then
    Resume
Else
    Exit Sub
End If
'
End Sub

Private Function ErrorCheck() as Boolean
    On Error GoTo 0
    Select Case Err.Number
        Case 53 'File not found
            If MsgBox(CStr(Err.Number) &  -  & _
            Err.Description, vbRetryCancel, App.Title) = vbRetry then
                ErrorCheck = True
            Else
                ErrorCheck = False
            End If
        Case Else
            MsgBox CStr(Err.Number) &  -  & _
            Err.Description, vbOKOnly, App.Title
           ErrorCheck = False
    End Select
End Function
As you can see, the error-routine is called and returns a value of True or False to signal if the error has been fixed. If the error was fixed, the program can continue.
Testing the Error Routine
When you are creating and testing your application, it is very important to test every error routine that you add to the application. One way to do this is to change the code to produce each error that might happen. An easier way is to use the Raise method of the Err object. This gives you the ability to generate any error that you want from within your code. The syntax of the Raise method is:
Err.Raise number, source, description, helpfile, helpcontext
Or, you can call the method by passing the name of each argument and its value:
Err.Raise Number:=71 ' Test the Disk not Ready error
To see how this statement works, add another command button to the form and insert the previous line of code. Now, run the application and click the new command button to see what happens. You should get the message box that you coded in the error-handling routine.

 
< previous page page_455 next page >

If you like this book, buy it!